/**
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain an copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.littlejie.app.slice;

import com.littlejie.app.ResourceTable;
import com.littlejie.circleprogress.DialProgress;
import com.littlejie.circleprogress.WaveProgress;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import com.littlejie.circleprogress.RoundProgressView;

/**
 * 功能展示
 *
 * @author fuchi
 * @since 2021-03-30
 */
public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    private static final int FOOTNUM = 10000;
    private static final int PERSENTNUM = 100;
    private static final int SPEEDNUM = 300;
    private RoundProgressView footProgressBar;
    private RoundProgressView persentProgressBar;
    private RoundProgressView progressProgressBar;
    private DialProgress speedProgress;
    private WaveProgress waveProgress;
    private Button clickToAdd;
    private Button clickToAddPersent;
    private Button clickToAddSpeed;
    private Button clickClearAdd;
    private Button clickToClearPersent;
    private Button clickToClearSpeed;
    private Button clickToChangePersent;
    private Button clickToClearChangePersent;
    private Button clickToWave; // 随机水波纹
    private Button clickToClearWave; // 水波纹清空

    /**
     * start
     *
     * @param intent
     */
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        initView();
    }

    /**
     * 初始化组件
     */
    private void initView() {
        footProgressBar = (RoundProgressView) findComponentById(ResourceTable.Id_foot_progress_bar);
        persentProgressBar = (RoundProgressView) findComponentById(ResourceTable.Id_persent_progress_bar);
        speedProgress = (DialProgress) findComponentById(ResourceTable.Id_speedProgress);
        waveProgress = (WaveProgress) findComponentById(ResourceTable.Id_waveProgress);
        progressProgressBar = (RoundProgressView) findComponentById(ResourceTable.Id_progress_progress_bar);
        clickToAdd = (Button) findComponentById(ResourceTable.Id_clickToAdd);
        clickToAddPersent = (Button) findComponentById(ResourceTable.Id_clickToAddPersent);
        clickToAddSpeed = (Button) findComponentById(ResourceTable.Id_clickToAddSpeed);
        clickClearAdd = (Button) findComponentById(ResourceTable.Id_clickClearAdd);
        clickToClearPersent = (Button) findComponentById(ResourceTable.Id_clickToClearPersent);
        clickToClearSpeed = (Button) findComponentById(ResourceTable.Id_clickToClearSpeed);
        clickToChangePersent = (Button) findComponentById(ResourceTable.Id_clickToChangePersent);
        clickToClearChangePersent = (Button) findComponentById(ResourceTable.Id_clickToClearChangePersent);
        clickToWave = (Button) findComponentById(ResourceTable.Id_clickToWave);
        clickToClearWave = (Button) findComponentById(ResourceTable.Id_clickToClearWave);

        clickToAdd.setClickedListener(this);
        clickToAddPersent.setClickedListener(this);
        clickToAddSpeed.setClickedListener(this);
        clickClearAdd.setClickedListener(this);
        clickToClearPersent.setClickedListener(this);
        clickToClearSpeed.setClickedListener(this);
        clickToChangePersent.setClickedListener(this);
        clickToClearChangePersent.setClickedListener(this);
        clickToWave.setClickedListener(this);
        clickToClearWave.setClickedListener(this);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    /** 点击事件
     * @param component
     */
    @Override
    public void onClick(Component component) {
        if (component.getId() == ResourceTable.Id_clickToAdd) {
            footProgressBar.setValue((float) Math.random() * FOOTNUM);
        } else if (component.getId() == ResourceTable.Id_clickToAddPersent) {
            persentProgressBar.setValue((float) Math.random() * PERSENTNUM);
        } else if (component.getId() == ResourceTable.Id_clickToAddSpeed) {
            speedProgress.setValue((float) Math.random() * SPEEDNUM);
        } else if (component.getId() == ResourceTable.Id_clickClearAdd) {
            footProgressBar.setValue(0);
        } else if (component.getId() == ResourceTable.Id_clickToClearPersent) {
            persentProgressBar.setValue(0);
        } else if (component.getId() == ResourceTable.Id_clickToClearSpeed) {
            speedProgress.setValue(0);
        } else if (component.getId() == ResourceTable.Id_clickToChangePersent) {
            progressProgressBar.setValue((float) Math.random() * PERSENTNUM);
        } else if (component.getId() == ResourceTable.Id_clickToClearChangePersent) {
            progressProgressBar.setValue(0);
        } else if (component.getId() == ResourceTable.Id_clickToWave) {
            waveProgress.setValue((float) Math.random() * PERSENTNUM);
        } else if (component.getId() == ResourceTable.Id_clickToClearWave) {
            waveProgress.setValue(0);
        }
    }

    public void showTest(){
        System.out.println("test");
    }
}
